package akaram.util.dice.tests;

import akaram.util.dice.DiceRoller;
import akaram.util.dice.DiceThrow;
import akaram.util.dice.RollDiceException;
import junit.framework.TestCase;

public class DiceRollerTest extends TestCase {

	public void testRollADice() {
		for(int i=0; i<10000; i++)
		{
			int thr = DiceRoller.rollADice(6);
			assertTrue(thr<=6);
			assertTrue(thr>=1);
		}
	}

	public void testRollDiceIntIntInt() {
		for(int i=0; i<10000; i++)
		{
			int thr = DiceRoller.rollDice(2, 6, 1);
			assertTrue(thr<=13);
			assertTrue(thr>=3);
		}
	}

	public void testRollFice() {
		DiceThrow dt = new DiceThrow(2,8,1);
		for(int i=0; i<10000; i++)
		{
			int thr = DiceRoller.rollDice(dt);
			assertTrue(thr<=17);
			assertTrue(thr>=3);
		}
	}

	public void testRollDiceString() {
		for(int i=0; i<1000; i++)
		{
			int thr;
			try {
				thr = DiceRoller.rollDice("2d10+1");
				assertTrue(thr<=21);
				assertTrue(thr>=3);
			} catch (RollDiceException e) {
				fail("Exception with 2d10+1.");
			}
		}
		
		try {
			int thr = DiceRoller.rollDice("jhsjhjss");
			fail("Exception expected!");
			thr = DiceRoller.rollDice("jhsjdhjss");
			fail("Exception expected!");
		} catch (RollDiceException e) {
		}
	}

}
